﻿using System;
using Loong.Dependency;

namespace Loong.AspNetCore.Models
{
    public class ErrorInfoBuilder : IErrorInfoBuilder, ISingletonDependency
    {
        private IExceptionToErrorInfoConverter Converter { get; set; }

        public ErrorInfoBuilder()
        {
            Converter = new DefaultErrorInfoConverter();
        }

        public ErrorInfo BuildForException(Exception exception)
        {
            return Converter.Convert(exception);
        }

        public void AddExceptionConverter(IExceptionToErrorInfoConverter converter)
        {
            converter.Next = Converter;
            Converter = converter;
        }
    }
}
